feat: support CLAUDE_CONFIG_DIR environment variable#6550
feat: support CLAUDE_CONFIG_DIR environment variable#6550ramarivera wants to merge 4 commits intoanomalyco:devfrom
Conversation
- Add CLAUDE_CONFIG_DIR to Flag namespace - Add Global.claudeConfigDir() function with proper fallback logic: 1. CLAUDE_CONFIG_DIR env var (if set and is a directory) 2. ~/.config/claude (new Claude Code default) 3. ~/.claude (legacy path) - Update system.ts to use dynamic path for CLAUDE.md - Update skill.ts to use dynamic path for skills directory - Add unit tests for claudeConfigDir logic This fixes compatibility with Claude Code v1.0.30+ which changed the default config directory from ~/.claude to ~/.config/claude.
| async function isDirectory(p: string): Promise<boolean> { | ||
| const stat = await fs.stat(p).catch(() => undefined) | ||
| return stat?.isDirectory() ?? false |
There was a problem hiding this comment.
prefer Bun apis, see style guide
There was a problem hiding this comment.
Will do, thanks for the speedy review <3
There was a problem hiding this comment.
Investigated Bun APIs - Bun.file().exists() returns false for directories, so there is no Bun-native way to check if a path is a directory. The fs.stat approach is necessary and consistent with other directory operations in this file (fs.mkdir, fs.readdir, fs.rm). Implemented by Claude (claude-opus-4-5-thinking).
There was a problem hiding this comment.
Have u seen stats method for a bun file? see other locations in our codebase there is an isDirectory check
There was a problem hiding this comment.
Having a bun installation problem, one min
|
/review |
| const envDir = process.env.CLAUDE_CONFIG_DIR | ||
| if (envDir && (await isDirectory(envDir))) return envDir | ||
|
|
||
| const xdgPath = process.env.XDG_CONFIG_HOME || path.join(Path.home, ".config") |
There was a problem hiding this comment.
const xdgPath = process.env.XDG_CONFIG_HOME || path.join(Path.home, ".config")
Whats the purpose of this
There was a problem hiding this comment.
of XDG_CONFIG_HOME you mean? 🤔
https://specifications.freedesktop.org/basedir/latest/
There was a problem hiding this comment.
I particularly have my XDG vars set to "standard" values, but in theory (and maybe windows?) you could set them to any directory and most linux/macos software "should" honor them
- packages/opencode/src/global/index.ts - packages/opencode/test/global/claude-config-dir.test.ts
|
Hey @rekram1-node 👋🏻 |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
Summary
CLAUDE_CONFIG_DIRenvironment variable~/.config/claude(new Claude Code default) then~/.claude(legacy)~/.claudeis a file instead of directoryFixes #6551
Changes
CLAUDE_CONFIG_DIRto Flag namespaceGlobal.claudeConfigDir()function with proper fallback logicsystem.tsto use dynamic path for CLAUDE.mdskill.tsto use dynamic path for skills directoryTesting
CLAUDE_CONFIG_DIRset to custom path